<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    {include file="/layout/scriptload"}
    <title>编辑复粉账号</title>
</head>
<body>
<div class="box">
    <!-- /.box-header -->
    <section class="content">
    <div class="box-body">
        <form role="form">
            <div class="form-group col-md-7" >
                <label>原始ID</label>
                <input type="text" id="gh_id" class="form-control" value="{$data.gh_id}" disabled="disabled">
            </div>
            <div class="form-group col-md-7" >
                <label>总分类</label>
                <select id="category_sum" class="form-control">
                    <option value="" >请选择...</option>
                    {volist name="category_sum" id="v"}
                    <option value="{$v.id}" {if condition="$v['id'] eq $data.category_sum"}selected="selected"{/if}>{$v.categoryname}</option>
                    {/volist}
                </select>
            </div>
            <div class="form-group col-md-7" >
                <label>子分类</label>
                <select id="category_child" class="form-control">
                    <option value="" >请选择...</option>
                    {volist name="category_child" id="vo"}
                    <option value="{$vo.id}" {if condition="$vo['id'] eq $data.category_child"}selected="selected"{/if}>{$vo.categoryname}</option>
                    {/volist}
                </select>
            </div>
            <div class="form-group col-md-7">
                <label>账号池</label>
                <select id="accountpool" class="form-control">
                    <option value="" >请选择...</option>
                    {volist name="pool" id="vol"}
                    <option value="{$vol.id}" {if condition="$vol['id'] eq $data['accountpool']"}selected="selected"{/if}>{$vol.poolname}</option>
                    {/volist}
                </select>
            </div>
            <div class="form-group col-md-7" >
                <label>点击链接图片数</label>
                <input type="text" class="form-control layui-input" value="{$data.link_img_num}" id="link_img_num">
            </div>
            <div class="form-group col-md-7" >
                <label>每十分钟控粉</label>
                <input type="text" id="limit_min" class="form-control" value="{$data.limit_min}">
            </div>
            <div class="form-group col-md-7" >
                <label>每小时控粉</label>
                <input type="text" id="limit_hour" class="form-control" value="{$data.limit_hour}">
            </div>
            <div class="form-group col-md-7" >
                <label>每天控粉</label>
                <input type="text" id="limit_day" class="form-control" value="{$data.limit_day}">
            </div>
            <input type="hidden" id="aid" value="{$data.id}">
            <div class="form-group col-md-7" >
                <div id="btn_save" class="btn pull-right" style="background: #18bc9c;color: #ffffff;">保存</div>
            </div>
        </form>
    </div>
    <!-- /.box-body -->
    </section>
</div>
</body>
<script>
    layui.use('laydate', function(){
        var laydate = layui.laydate;

        //执行一个laydate实例
        laydate.render({
            elem: '#endtime', //指定元素
            type: 'datetime'
        });
    });
    $(function(){
        //获取子分类
        $("#category_sum").change(function () {
            var _id = $(this).val();
            $.ajax({
                type: 'post',
                cache: false,
                url: '{:url("admin/Replyfans/getCategoryChild")}',
                data: {cid:_id},
                success: function(data) {
                    if (data.code == "0") {
                        $("#category_child option").remove();
                        var html = '<option value="">请选择...</option>';
                        $("#category_child").append(html);
                        $.each(data.info, function (index, item) {
                            var html = '<option value="' + item.id + '">' + item.categoryname + '</option>';
                            $("#category_child").append(html);
                        });
                    }
                }
            })
        });
        //获取账号池
        $("#category_child").change(function () {
            var _id = $(this).val();
            $.ajax({
                type: 'post',
                cache: false,
                url: '{:url("admin/Replyfans/getShieldRule")}',
                data: {cid:_id},
                success: function(data) {
                    if (data.code == "0") {
                        $("#accountpool option").remove();
                        var html = '<option value="">请选择...</option>';
                        $("#accountpool").append(html);
                        $.each(data.info, function (index, item) {
                            var html = '<option value="' + item.id + '">' + item.poolname + '</option>';
                            $("#accountpool").append(html);
                        });
                    }
                }
            })
        });
        $('#btn_save').click(function () {
            var _id = $('#aid').val();
            var _category_sum = $('#category_sum').val();
            var _category_child = $('#category_child').val();
            var _accountpool = $('#accountpool').val();
            var _link_img_num = $('#link_img_num').val();
            var _limit_min = $('#limit_min').val();
            var _limit_hour = $('#limit_hour').val();
            var _limit_day = $('#limit_day').val();
            if(_category_sum == ''){
                layerAlert('请选择总分类');
                return false;
            }
            if(_category_child == ''){
                layerAlert('请选择子分类');
                return false;
            }
            if(_accountpool == ''){
                layerAlert('请选择账号池');
                return false;
            }
            $.ajax({
                type: 'post',
                cache: false,
                url: '{:url("admin/Replyfans/doEditAccount")}',
                data: {id:_id,category_sum:_category_sum,category_child:_category_child,accountpool:_accountpool,link_img_num:_link_img_num,limit_min:_limit_min,limit_hour:_limit_hour,limit_day:_limit_day},
                success: function(data) {
                    if(data.code=="0")
                    {
                        layerAlert(data.msg,function(){
                            parent.relist();
                            layerParentClose();
                        });
                    }else{
                        layerAlert(data.msg);
                    }
                }
            })
        })
    })
</script>
</html>